package com.scs.application.modules.dept.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.dept.entity.UseMerge;
import com.scs.application.modules.dept.entity.UseMergeDtl;
import com.scs.application.modules.dept.service.UseMergeDtlService;
import com.scs.application.modules.dept.service.UseMergeService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 */
@RestController
@RequestMapping("/dept/use_merge_dtl")
public class UseMergeDtlController extends CrudController<UseMergeDtlService, UseMergeDtl>{
    @Autowired
    private UseMergeService useMergeService;

    /**
     * 自动合单
     * @param useMergeId
     * @return
     */
    @PostMapping("/autoMerge")
    public RestResult autoMerge(@RequestParam(name = "useMergeId") String useMergeId) {
        boolean isOk = service.autoMerge(useMergeId);
        if (!isOk) {
            return RestResult.error("数据保存失败");
        }
        return RestResult.ok("数据保存成功");
    }

    /**
     * 自动合单(病人消耗单)
     * @param useMergeId
     * @return
     */
    @PostMapping("/autoMergeOprtUse")
    @Deprecated
    public RestResult autoMergeOprtUse(@RequestParam(name = "useMergeId") String useMergeId) {
        UseMerge useMerge = useMergeService.getById(useMergeId);

        String inpatientNo = useMerge.getInpatientNo();

        boolean isOk = service.autoMergeOprtUse(inpatientNo, useMergeId,useMerge.getFlagLine(),useMerge.getDeptId());
        if (!isOk) {
            return RestResult.error("数据保存失败");
        }
        return RestResult.ok("数据保存成功");
    }
}
